/*
 * @Description: 不同方法进行集合的遍历
 * @Author: Aroma
 * @Date: 2024-10-09 10:46:19
 * @LastEditors: Aroma
 * @LastEditTime: 2024-10-09 17:24:11
 * @别瞎看: 你个无脑牛马
 */

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * Test2
 */
public class Test2 {

    public static void main(String[] args) {
        ArrayList arrayList=new ArrayList<>();
        arrayList.addAll(Arrays.asList(1,2,3,4,5));
        //直接打印集合
        System.out.println("直接打印集合");
        System.out.println(arrayList);
        //普通for循环遍历
        System.out.println("普通for循环遍历");
        for(int i=0;i<arrayList.size();i++){
            System.out.println(arrayList.get(i));
        }
        //增强for循环
        System.out.println("增强for循环");
        for(Object object:arrayList){
            System.out.println(object);
        }
         // 迭代器
        System.out.println("迭代器");
        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
        Object object = iterator.next();
        System.out.println(object);
        }
        // lambda表达式
        System.out.println("lambda表达式");
        arrayList.forEach((object) -> {
        System.out.println(object);
        });
        // 匿名内部类
        System.out.println("匿名内部类");
        arrayList.forEach(new Consumer() {
            @Override
            public void accept(Object t) {
                System.out.println(t);
            }
        });
    }
}